package main

import (
    "flag"
    "fmt"
    "os"
    "bufio"
    "myindexer"
    "myutils"
    "mysearch"
)

func main() {
    var orderType string  // 命令类型
    var indexName string  // 建立的索引名称
    var filename string  // 数据文件

    flag.StringVar(&orderType, "type", "index", "启动选项")
    flag.StringVar(&indexName, "index", "test", "索引名称")
    flag.StringVar(&filename, "file", "test.txt", "源文件")

    myutils.GSegmenter = myutils.NewSegmenter("./data/dictionary.txt");

    if orderType == "index" {
        indexer := myindexer.NewIndexer(indexName)

        datafile, err := os.Open(filename)
        if err != nil {
            fmt.Println(fmt.Errorf("Error:%v,filename:[%v] not found\n", err, filename))
            return
        }
        defer datafile.Close()

        scanner := bufio.NewScanner(datafile)
        for scanner.Scan() {
            indexer.AddDocument(scanner.Text())
        }

        indexer.SyncIndex()
    } else if orderType == "search" {
        var key string
        var pageSize int
        var pageCount int
        var indexName str
        mysearch.NewSearch()
    }
}
